import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/

export const constantRouterMap = [
  {path: '/login', component: () => import('@/views/login/index'), hidden: true},
  {path: '/404', component: () => import('@/views/404'), hidden: true},
  {
    path: '',
    component: Layout,
    // redirect: '/home',
    // meta: {title: '首页', icon: 'home'},
    redirect: '/user/userList',
    meta: {title: '用户管理', icon: 'user'},
    children: [{
        path: 'userList',
        name: 'userList',
        component: () => import('@/views/user/list/index'),
        meta: {title: '注册用户列表', icon: 'product-list'}
      },
    ]
  }
]

export const asyncRouterMap = [
  {
    path: '/user',
    component: Layout,
    redirect: '/user/userList',
    name: 'user',
    meta: {title: '用户管理', icon: 'user'},
    children: [{
      path: 'userList',
      name: 'userList',
      component: () => import('@/views/user/list/index'),
      meta: {title: '注册用户列表', icon: 'product-list'}
    }]
  },
  {
    path: '/audit',
    component: Layout,
    redirect: '/audit/sensitiveFilter',
    name: 'audit',
    meta: {title: '审核中心', icon: 'user'},
    children: [{
      path: 'sensitiveFilter',
      name: 'sensitiveFilter',
      component: () => import('@/views/audit/sensitive/index'),
      meta: {title: '敏感词过滤', icon: 'product-list'}
    }]
  },
  {
    path: '/content',
    component: Layout,
    redirect: '/content/destination',
    name: 'content',
    meta: {title: '内容管理', icon: 'product'},
    children: [{
      path: 'destination',
      name: 'destination',
      component: () => import('@/views/content/destination/index'),
      meta: {title: '目的地推荐', icon: 'product-list'}
    },{
      path: 'manage',
      name: 'manage',
      component: () => import('@/views/content/manage/index'),
      meta: {title: '目的地管理', icon: 'product-list'}
    }]
  },
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/activityList',
    name: 'activity',
    meta: {title: '活动管理', icon: 'product'},
    children: [{
      path: 'activityList',
      name: 'activityList',
      component: () => import('@/views/activity/list/index'),
      meta: {title: '活动列表', icon: 'product-list'}
    },{
      path: 'notice',
      name: 'notice',
      component: () => import('@/views/activity/notice/index'),
      meta: {title: '票务须知管理', icon: 'product-list'}
    },{
      path: 'tour',
      name: 'tour',
      component: () => import('@/views/activity/tour/index'),
      meta: {title: '巡演关联管理', icon: 'product-list'}
    }]
  },
  {
    path: '/ticket',
    component: Layout,
    redirect: '/ticket/stand',
    name: 'ticket',
    meta: {title: '票务顾问管理', icon: 'product'},
    children: [{
      path: 'stand',
      name: 'stand',
      component: () => import('@/views/ticket/stand/index'),
      meta: {title: '待审核', icon: 'product-list'}
    },
    {
      path: 'certified',
      name: 'certified',
      component: () => import('@/views/ticket/certified/index'),
      meta: {title: '已认证', icon: 'product-list'}
    },
    {
      path: 'dismiss',
      name: 'dismiss',
      component: () => import('@/views/ticket/stand/index'),
      meta: {title: '已撤销', icon: 'product-list'}
    },
    {
      path: 'refuse',
      name: 'refuse',
      component: () => import('@/views/ticket/stand/index'),
      meta: {title: '已拒绝', icon: 'product-list'}
    }]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/confirm',
    name: 'order',
    meta: {title: '订单管理', icon: 'order'},
    children: [{
      path: 'confirm',
      name: 'confirm',
      component: () => import('@/views/order/confirm/index'),
      meta: {title: '待确认', icon: 'order-setting'}
    },
    {
      path: 'obligation',
      name: 'obligation',
      component: () => import('@/views/order/obligation/index'),
      meta: {title: '待付款', icon: 'order-return'}
    },
    {
      path: 'close',
      name: 'close',
      component: () => import('@/views/order/close/index'),
      meta: {title: '已关闭', icon: 'order-return-reason'}
    },
    {
      path: 'settlement',
      name: 'settlement',
      component: () => import('@/views/order/settlement/index'),
      meta: {title: '待结算', icon: 'order-setting'}
    },
    {
      path: 'settled',
      name: 'settled',
      component: () => import('@/views/order/settled/index'),
      meta: {title: '已结算', icon: 'product-list'}
    }]
  },
  {
    path: '/refund',
    component: Layout,
    redirect: '/refund/reviewed',
    name: 'refund',
    meta: {title: '退款管理', icon: 'sms'},
    children: [{
      path: 'reviewed',
      name: 'reviewed',
      component: () => import('@/views/refund/reviewed/index'),
      meta: {title: '待审核', icon: 'sms-flash'}
    },
    {
      path: 'refunded',
      name: 'refunded',
      component: () => import('@/views/refund/refunded/index'),
      meta: {title: '待退款', icon: 'sms-coupon'}
    },
    {
      path: 'successful',
      name: 'successful',
      component: () => import('@/views/refund/successful/index'),
      meta: {title: '退款成功', icon: 'sms-new'}
    }]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/systemList',
    name: 'system',
    meta: {title: '系统账号', icon: 'ums-admin'},
    children: [{
      path: 'systemList',
      name: 'systemList',
      component: () => import('@/views/ums/admin/index'),
      meta: {title: '系统账号', icon: 'ums-admin'}
    }]
  },
  {
    path: '/play',
    component: Layout,
    redirect: '/play/playManage',
    name: 'play',
    meta: {title: '角色管理', icon: 'ums-role'},
    children: [{
        path: 'playManage',
        name: 'playManage',
        component: () => import('@/views/ums/role/index'),
        meta: {title: '角色管理', icon: 'ums-role'}
      },
      {
        path: 'allocPlayMenu',
        name: 'allocPlayMenu',
        component: () => import('@/views/ums/role/allocMenu'),
        meta: {title: '分配菜单'},
        hidden: true
      },
      {
        path: 'allocPlayResource',
        name: 'allocPlayResource',
        component: () => import('@/views/ums/role/allocResource'),
        meta: {title: '分配资源'},
        hidden: true
      },
    ]
  },
  {
    path: '/versions',
    component: Layout,
    redirect: '/versions/versionsManage',
    name: 'versions',
    meta: {title: '版本管理', icon: 'order'},
    children: [{
      path: 'versionsManage',
      name: 'versionsManage',
      component: () => import('@/views/versions/manage/index'),
      meta: {title: '软件版本管理', icon: 'order'}
    }]
  },
  {
    path: '/document',
    component: Layout,
    redirect: '/document/help',
    name: 'document',
    meta: {title: '文档管理', icon: 'product'},
    children: [
      {
        path: 'help',
        name: 'help',
        component: () => import('@/views/document/help/index'),
        meta: {title: '帮助中心FAQ', icon: 'product-list'}
      },
      {
        path: 'rule',
        name: 'rule',
        component: () => import('@/views/document/rule/index'),
        meta: {title: '规则与条款', icon: 'product-attr'}
      },
      {
        path: 'about',
        name: 'about',
        component: () => import('@/views/document/about/index'),
        meta: {title: '关于我们', icon: 'product-add'}
      },
    ]
  },
  {
    path:'/ums',
    component: Layout,
    redirect: '/ums/menu',
    name: 'ums',
    meta: {title: '权限配置', icon: 'ums'},
    children: [
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/ums/menu/index'),
        meta: {title: '菜单列表', icon: 'ums-menu'}
      },
      {
        path: 'addMenu',
        name: 'addMenu',
        component: () => import('@/views/ums/menu/add'),
        meta: {title: '添加菜单'},
        hidden: true
      },
      {
        path: 'updateMenu',
        name: 'updateMenu',
        component: () => import('@/views/ums/menu/update'),
        meta: {title: '修改菜单'},
        hidden: true
      },
      {
        path: 'resource',
        name: 'resource',
        component: () => import('@/views/ums/resource/index'),
        meta: {title: '资源列表', icon: 'ums-resource'}
      },
      {
        path: 'resourceCategory',
        name: 'resourceCategory',
        component: () => import('@/views/ums/resource/categoryList'),
        meta: {title: '资源分类'},
        hidden: true
      }
    ]
  },
  
  {path: '*', redirect: '/404', hidden: true}
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
})

// 新增处理相同路径刷新时报错的问题
const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
      return VueRouterPush.call(this, to).catch(err => err)
}